{extend name="v1/layout/base"}
{block name="content"}
<div class="layuimini-main">
  <script type="text/html" id="toolbar">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
      <button class="layui-btn layui-btn-normal  layui-btn-sm" lay-event="authRuleUpdate" data-url="/{:config('manage.manage_name')}/{:config('manage.version')}/Admin/authRuleUpdate"><i class="layui-icon layui-icon-refresh-3"></i>更新权限节点</button>
    </div>
  </script>
  <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
</div>
{/block}
{block name="myScript"}
<script>
  layui.use(['table', 'layer', 'util', 'form', 'treetable'], function() {
    var $ = layui.jquery,
      table = layui.table,
      treetable = layui.treetable,
      layer = layui.layer,
      util = layui.util,
      form = layui.form,
      insTab = treetable.render({
        elem: '#currentTableId',
        url: '/{:config("manage.manage_name")}/{:config("manage.version")}/Admin/authRule',
        toolbar: '#toolbar',
        defaultToolbar: ['filter'],
        page: false,
        tree: {
          iconIndex: 1,
          isPidData: true,
          openName: 'auth_rule_id',
          idName: 'auth_rule_id',
          pidName: 'parent_id',
          arrowType: 'arrow2',
          getIcon: 'ew-tree-icon-style2'
        },
        cols: [
          [{
              field: 'auth_rule_id',
              width: '5%',
              title: 'ID',
              sort: true
            },
            {
              field: 'auth_name',
              width: '15%',
              title: '节点名称'
            },
            {
              field: 'auth_controller',
              width: '10%',
              title: '节点控制器'
            },
            {
              field: 'auth_action',
              title: '节点方法',
              width: '10%'
            },
            {
              field: 'linkurl',
              title: '节点链接',
              width: '25%'
            },
            {
              field: 'update_time',
              width: '25%',
              title: '最后更新时间',
            }
          ]
        ],
        skin: 'line',
        done: function() {
          layer.closeAll('loading');
        }
      });
    // 顶部操作工具
    treetable.on('toolbar(currentTableId)', function(obj) {
      var url = $(this).attr('data-url');
      switch (obj.event) {
        case 'reseve':
          insTab.reload();
          break;
        case 'authRuleUpdate':
          https(url, {}, 'post', true, '正在更新权限节点数据').then(res => {
            if (res.result_code == 200) {
              insTab.reload();
            }
          })
          break;
      }
    })
  });
</script>
{/block}
